package com.lins.framework.ui.home.product;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.lins.framework.R;
import com.lins.framework.mvpframe.base.BaseFrameActivity;
import com.lins.framework.utils.image.glide.GlideImageLoader;
import com.lins.framework.utils.tip.ToastUtil;
import com.lins.framework.utils.toolbar.AppToolBar;
import com.lins.framework.widget.banner.Banner;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Admin on 2017/3/14.
 */

public class ProductListActivity extends BaseFrameActivity<ProductListPresenter, ProductListModel>
        implements ProductListContract.View, Banner.OnBannerClickListener {

    @BindView(R.id.id_btn)
    Button idBtn;
    @BindView(R.id.id_tv)
    TextView idTv;
    @BindView(R.id.id_img)
    ImageView idImg;
    @BindView(R.id.id_Banner)
    Banner idBanner;
    @BindView(R.id.id_toolbar)
    Toolbar idToolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.product_list);
        ButterKnife.bind(this);
        context = this;
        mPresenter.getTopBanner(1243);
        // TODO：用户信息保存本地
        // TODO:使用CloudReader项目中的，BaseFragment的Loading功能。
        // TODO：鸿洋的通用RecyclerviewAdapter
    }

    @Override
    public void initView() {
        new AppToolBar(this, idToolbar, "商品列表");
    }

    @OnClick(R.id.id_btn)
    public void onClick() {
        mPresenter.getProductList(1);
    }

    @Override
    public void setBtnText(ProductListBean bean) {
        idTv.setText(bean.getList().get(0).getTitle());
        GlideImageLoader.getInstance().displayImage(this, bean.getList().get(0).getThumb(), idImg);
    }

    @Override
    public void setBannerData(ArrayList<TopBannerBean> mList) {
        List<String> images = new ArrayList<>();
        List<String> titles = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            TopBannerBean bean = mList.get(0);
            images.add(bean.getThumb());
            titles.add(bean.getFirsttext());
        }
//        for (int i = 0; i < mList.size(); i++) {
//            TopBannerBean bean = mList.get(i);
//            images.add(bean.getThumb());
//            titles.add(bean.getFirsttext());
//        }
        idBanner.setImages(images)
                .setBannerTitles(titles)
                .setImageLoader(GlideImageLoader.getInstance())
                .setOnBannerClickListener(this)
                .start();
    }

    @Override
    public void OnBannerClick(int position) {
        ToastUtil.showToast(context, "position:" + position);
    }
}
